/**
 * rust中允许为一个特质指定限定条件，方式一就是指定要实现的父级特质
 * 而具体实现其实是要求类型实现所有的特质
 * 这种对于特质的限定，其实是对于类型的限定
 */
use std::fmt;

struct Point {
    x: i32,
    y: i32,
}
trait Copy{
    fn copy(&self) -> Self;
}
trait OutlinePrint: fmt::Display+Copy{
    fn outline_print(&self) {
        let output = self.to_string();
        let len = output.len();
        println!("{}", "*".repeat(len + 4));
        println!("*{}*", " ".repeat(len + 2));
        println!("* {output} *");
        println!("*{}*", " ".repeat(len + 2));
        println!("{}", "*".repeat(len + 4));
    }
}

impl OutlinePrint for Point {}
impl fmt::Display for Point {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "({}, {})", self.x, self.y)
    }
}
impl Copy for Point {
    fn copy(&self) -> Self {
            Point { x: self.x, y: self.y }
    }
}

fn main() {
    let p = Point { x: 10, y: 20 };
    p.outline_print();
    let c=p.copy();
    c.outline_print();
}



